import store from '../store'
import request from '@/utils/request.js' // 导入  定义所有频道接口
const getarticleDetails = (id) => {
  // 必须加return!!
  return request({
    url: '/v1_0/articles/' + id
  })
}

const setTheAuthorId = (id) => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    // headers: {
    //   Authorization: `Bearer ` + `${store.state.token}`
    // },
    data: {
      target: toString(id)
    }
  })
}

const unsubscribe = (id) => {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + id
  })
}
//得到评论
const getComments = (id) => {
  return request({
    method: 'GET',
    url: '/v1_0/comments',
    // headers: {
    //   Authorization: `Bearer ` + `${store.state.token}`
    // },
    params: {
      type: 'a',
      source: id,
      limit: 50
    }
  })
}

const getTheArticleLikes = (id) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    // headers: {
    //   Authorization: `Bearer ` + `${store.state.token}`
    // },
    data: {
      target: id
    }
  })
}
const setNotLike = (id) => {
  return request({
    method: 'DELETE',
    url: '/v1_0/article/likings/' + id
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`
    // },

  })
}

// 发布评论
const releaseComment = (id, str) => {
  return request({
    method: 'POST',
    url: '/v1_0/comments',
    data: {
      target: id,
      content: str
    }
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`
    // },

  })
}
// 点赞
const setLike = (id) => {
  return request({
    method: 'POST',
    url: '/v1_0/comment/likings',
    data: {
      target: id
    }
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`
    // },

  })
}
// 取消点赞
const cancelSome = (id) => {
  return request({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + id
    // headers: {
    //   Authorization: `Bearer ` + `${store.state.token}`
    // },

  })
}


export {
  // 文章详情
  getarticleDetails,
  // 作者id
  setTheAuthorId,
  // 取消关注
  unsubscribe,
  // 得到评论
  getComments,
  // 喜欢文章
  getTheArticleLikes,
  // 取消喜欢文章
  setNotLike,
  // 发布评论
  releaseComment,
  // 点赞
  setLike,
  // 取消点赞
  cancelSome

}
